package com.xian.java.sink;


import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.functions.sink.RichSinkFunction;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

public class MyHbaseSink extends RichSinkFunction {

    private Connection con = null;

    private int i = 0;

    @Override
    public void open(Configuration parameters) throws Exception {
        super.open(parameters);

        org.apache.hadoop.conf.Configuration conf = HBaseConfiguration.create();

        String zk ="";
        String hbaseTable="";

        conf.set("hbase.zookeeper.quorum", zk);
        TableName tableName = TableName.valueOf(hbaseTable); //表名
        con = ConnectionFactory.createConnection(conf);


    }

    @Override
    public void close() throws Exception {
        super.close();
        if(null != con){
            con.close();
        }
    }

    @Override
    public void invoke(Object value, Context context) throws Exception {
        System.out.println("调用com.xian.java.sink.MyHbaseSink.invoke次数："+(++i));

        System.out.println(value);


    }
}
